<?php function tema_admin_head() { ?>
<style>

h2 { margin-bottom: 20px; }
.title { margin: 0px !important; background: #D4E9FA; padding: 10px; font-family: Georgia, serif; font-weight: normal !important; letter-spacing: 1px; font-size: 18px; }
.container { background: #EAF3FA; padding: 10px; }
.maintable { font-family:"Lucida Grande","Lucida Sans Unicode",Arial,Verdana,sans-serif; background: #EAF3FA; margin-bottom: 20px; padding: 10px 0px; }
.mainrow { padding-bottom: 10px !important; border-bottom: 1px solid #D4E9FA !important; float: left; margin: 0px 10px 10px 10px !important; }
.titledesc { font-size: 14px; font-weight:bold; width: 220px !important; margin-right: 20px !important; }
.forminp { width: 700px !important; valign: middle !important; }
.forminp input, .forminp select, .forminp textarea { margin-bottom: 9px !important; background: #fff; border: 1px solid #D4E9FA; width: 500px; padding: 4px; font-family:"Lucida Grande","Lucida Sans Unicode",Arial,Verdana,sans-serif; font-size: 12px; }
.forminp span { font-size: 10px !important; font-weight: normal !important; ine-height: 14px !important; }
.info { background: #FFFFCC; border: 1px dotted #D8D2A9; padding: 10px; color: #333; }
.forminp .checkbox { width:20px }
.info a { color: #333; text-decoration: none; border-bottom: 1px dotted #333 }
.info a:hover { color: #666; border-bottom: 1px dotted #666; }
.warning { background: #FFEBE8; border: 1px dotted #CC0000; padding: 10px; color: #333; font-weight: bold; }

</style>
<?php }

// VARIABLES

$themename = "Impatience";
$shortname = "impa";
$manualurl = '';
$options = array();

$template_path = get_bloginfo('template_directory');

$other_entries = array("Select a number:","1","2","3","4","5","6","7","8","9","10","11","12","13","14","15","16","17","18","19");

$options = array (
				array(	"name" => "Optiuni generale",
						"type" => "heading"),
				array(	"name" => "Arata Navigatia Sus",
						"desc" => "Aici decizi daca sa arat navigatia sus sau nu!",
						"id" => $shortname."_navigatie_sus",
						"std" => "true",
						"type" => "checkbox"),
				array(	"name" => "Arata Navigatia Jos",
						"desc" => "Aici decizi daca sa arat navigatia jos sau nu!",
						"id" => $shortname."_navigatie_jos",
						"std" => "true",
						"type" => "checkbox"),
				array(	"name" => "Arata linkuri rss in footer",
						"desc" => "Daca aceasta optiune este activa, linkuri spre RSS(comentarii si posturi) vor fi introduse in footer",
						"id" => $shortname."_rss_footer",
						"std" => "true",
						"type" => "checkbox"),
				array(	"name" => "Arata Powered by Wordpress in footer",
						"desc" => "Daca activezi aceasta optiune, voi introduce un text in footer care duce spre wordpress.org(suporta wordpress activand aceasta optiune)",
						"id" => $shortname."_pwdby_footer",
						"std" => "true",
						"type" => "checkbox"),
				array(	"name" => "Arata categoriile inainte de postari pe orice pagina",
						"desc" => "Daca aceasta functie este activata, pe fiecare pagina, inainte de postari, sunt afisate categoriile blogului!",
						"id" => $shortname."_categorii",
						"std" => "false",
						"type" => "checkbox"),	
				array(	"name" => "Optiuni afisare articole",
						"type" => "heading"),
				array(	"name" => "Arata autorul postarii",
						"desc" => "Arata sau nu autorul postarilor",
						"id" => $shortname."_arata_autor",
						"std" => "true",
						"type" => "checkbox"),
				array(	"name" => "Arata categoriile",
						"desc" => "Arata categoriile postarilor",
						"id" => $shortname."_arata_categorii",
						"std" => "true",
						"type" => "checkbox"),
				array(	"name" => "Arata etichete(taguri)",
						"desc" => "Arata etichetele(tagurile) postarilor",
						"id" => $shortname."_arata_etichete",
						"std" => "true",
						"type" => "checkbox"),
				array(	"name" => "Arata retele sociale",
						"desc" => "Cu aceasta optiune activata, userii vor putea foarte usor sa adauge articolul pe retelele sociale(digg, etc).",
						"id" => $shortname."_arata_retele",
						"std" => "true",
						"type" => "checkbox"),
				array(	"name" => "Arata link spre editare(staff only)",
						"desc" => "Cu aceasta optiune activata, administratorii vor putea sa editeze articolul cu un singur click!",
						"id" => $shortname."_arata_editeaza",
						"std" => "true",
						"type" => "checkbox"),
				array(	"name" => "Format data",
						"desc" => "Formatul in care este afisata data(php.net/date)",
						"id" => $shortname."_format_data",
						"std" => "m/j/y",
						"type" => "text"),	
				array(	"name" => "Optiuni comentarii",
						"type" => "heading"),
				array(	"name" => "Arata taguri XHTML",
						"desc" => "Arata o lista cu toate tagurile pe care utilizatorul le poate folosi",
						"id" => $shortname."_taguri_xhtml",
						"std" => "true",
						"type" => "checkbox"),
				array(	"name" => "Email-ul autorului!",
						"desc" => "Introdu aici emailul autorului principal, pentru ca sa putem face deosebire intre comentarii!",
						"id" => $shortname."_email_autor",
						"std" => "",
						"type" => "text"),
																														
		  );


function tema_add_admin() {

	 global $themename, $options;
	
	if ( $_GET['page'] == basename(__FILE__) ) {	
        if ( 'save' == $_REQUEST['action'] ) {
	
                foreach ($options as $value) {
					if($value['type'] != 'multicheck'){
                    	update_option( $value['id'], $_REQUEST[ $value['id'] ] ); 
					}else{
						foreach($value['options'] as $mc_key => $mc_value){
							$up_opt = $value['id'].'_'.$mc_key;
							update_option($up_opt, $_REQUEST[$up_opt] );
						}
					}
				}

                foreach ($options as $value) {
					if($value['type'] != 'multicheck'){
                    	if( isset( $_REQUEST[ $value['id'] ] ) ) { update_option( $value['id'], $_REQUEST[ $value['id'] ]  ); } else { delete_option( $value['id'] ); } 
					}else{
						foreach($value['options'] as $mc_key => $mc_value){
							$up_opt = $value['id'].'_'.$mc_key;						
							if( isset( $_REQUEST[ $up_opt ] ) ) { update_option( $up_opt, $_REQUEST[ $up_opt ]  ); } else { delete_option( $up_opt ); } 
						}
					}
				}
						
				header("Location: admin.php?page=functions.php&saved=true");								
			
			die;

		} else if ( 'reset' == $_REQUEST['action'] ) {
			delete_option('sandbox_logo');
			
			header("Location: admin.php?page=functions.php&reset=true");
			die;
		}

	}

add_menu_page($themename." Options", $themename." Options", 'edit_themes', basename(__FILE__), 'tema_page');

}

function tema_page (){

		global $options, $themename, $manualurl;
		
		?>

<div class="wrap">

    			<form action="<?php echo $_SERVER['REQUEST_URI']; ?>" method="post">

						<h2><?php echo $themename; ?> - Optiuni</h2>

						<?php if ( $_REQUEST['saved'] ) { ?><div style="clear:both;height:20px;"></div><div class="warning"><?php echo $themename; ?> - Optiunile au fost salvate!</div><?php } ?>
						<?php if ( $_REQUEST['reset'] ) { ?><div style="clear:both;height:20px;"></div><div class="warning"><?php echo $themename; ?> - Optiunile au fost resetate!</div><?php } ?>						
						
						<div style="clear:both;height:20px;"></div>
						
						<div class="info">
						
							<div style="width: 70%; float: left; display: inline;padding-top:4px;"><strong>Nu stii ce sa faci aici?</strong> <a href="<?php echo $manualurl; ?>" target="_blank">Cere ajutor</a></div>
							<div style="width: 30%; float: right; display: inline;text-align: right;"><input name="save" type="submit" value="Salveaza setarile!" /></div>
							<div style="clear:both;"></div>
						
						</div>	    			
						
						<!--START: GENERAL SETTINGS-->
     						
     						<table class="maintable">
     							
							<?php foreach ($options as $value) { ?>
	
									<?php if ( $value['type'] <> "heading" ) { ?>
	
										<tr class="mainrow">
										<td class="titledesc"><?php echo $value['name']; ?></td>
										<td class="forminp">
		
									<?php } ?>		 
	
									<?php
										
										switch ( $value['type'] ) {
										case 'text':
		
									?>
									
		        							<input name="<?php echo $value['id']; ?>" id="<?php echo $value['id']; ?>" type="<?php echo $value['type']; ?>" value="<?php if ( get_settings( $value['id'] ) != "") { echo get_settings($value['id']); } else { echo $value['std']; } ?>" />
		
									<?php
										
										break;
										case 'select':
		
									?>
		
	            						<select name="<?php echo $value['id']; ?>" id="<?php echo $value['id']; ?>">
	                					<?php foreach ($value['options'] as $option) { ?>
	                						<option<?php if ( get_settings( $value['id'] ) == $option) { echo ' selected="selected"'; } elseif ($option == $value['std']) { echo ' selected="selected"'; } ?>><?php echo $option; ?></option>
	                					<?php } ?>
	            						</select>
		
									<?php
		
										break;
										case 'textarea':
										$ta_options = $value['options'];
		
									?>
									
										<textarea name="<?php echo $value['id']; ?>" id="<?php echo $value['id']; ?>" cols="<?php echo $ta_options['cols']; ?>" rows="8"><?php  if( get_settings($value['id']) != "") { echo stripslashes(get_settings($value['id'])); } else { echo $value['std']; } ?></textarea>
		
									<?php
										
										break;
										case "radio":
		
 										foreach ($value['options'] as $key=>$option) { 
				
													$radio_setting = get_settings($value['id']);
													
													if($radio_setting != '') {
		    											
		    											if ($key == get_settings($value['id']) ) { $checked = "checked=\"checked\""; } else { $checked = ""; }
													
													} else {
													
														if($key == $value['std']) { $checked = "checked=\"checked\""; } else { $checked = ""; }
									} ?>
									
	            					<input type="radio" name="<?php echo $value['id']; ?>" value="<?php echo $key; ?>" <?php echo $checked; ?> /><?php echo $option; ?><br />
		
									<?php }
		 
										break;
										case "checkbox":
										
										if(get_settings($value['id'])) { $checked = "checked=\"checked\""; } else { $checked = ""; }
									
									?>
		            				
		            				<input type="checkbox" class="checkbox" name="<?php echo $value['id']; ?>" id="<?php echo $value['id']; ?>" value="true" <?php echo $checked; ?> />
		
									<?php
		
										break;
										case "multicheck":
		
 										foreach ($value['options'] as $key=>$option) {
 										
	 											$tema_key = $value['id'] . '_' . $key;
												$checkbox_setting = get_settings($tema_key);
				
 												if($checkbox_setting != '') {
		    		
		    											if (get_settings($tema_key) ) { $checked = "checked=\"checked\""; } else { $checked = ""; }
				
												} else { if($key == $value['std']) { $checked = "checked=\"checked\""; } else { $checked = ""; }
				
									} ?>
									
	            					<input type="checkbox" class="checkbox" name="<?php echo $tema_key; ?>" id="<?php echo $tema_key; ?>" value="true" <?php echo $checked; ?> /><label for="<?php echo $tema_key; ?>"><?php echo $option; ?></label><br />
									
									<?php }
		 
										break;
										case "heading":

									?>
									
										</table> 
		    							
		    									<h3 class="title"><?php echo $value['name']; ?></h3>
										
										<table class="maintable">
		
									<?php
										
										break;
										default:
										break;
									
									} ?>
	
									<?php if ( $value['type'] <> "heading" ) { ?>
	
										<?php if ( $value['type'] <> "checkbox" ) { ?><br/><?php } ?><span><?php echo $value['desc']; ?></span>
										</td></tr>
	
									<?php } ?>		
	
							<?php } ?>	
							
							</table>	

							<p class="submit">
								<input name="save" type="submit" value="Salveaza setarile" />    
								<input type="hidden" name="action" value="save" />
							</p>							
							
							<div style="clear:both;"></div>		
						
												
             
            </form>

</div>

<div style="clear:both;height:20px;"></div>
 
 <?php

}
add_action('admin_menu', 'tema_add_admin');
add_action('admin_head', 'tema_admin_head');
#other
	if ( function_exists('register_sidebar') ) {  
		register_sidebar(array('name'=>'sidebar'));  
		register_sidebar(array('name'=>'subfooterleft'));  
		register_sidebar(array('name'=>'subfootercenter'));  
		register_sidebar(array('name'=>'subfooterright'));
	}

# edit this function to take an arg of short or long
function display_post() { ?>
	<div class="post" id="post-<?php the_ID(); ?>">
		<h2><em class="comment_link"><a href="<?php echo comments_link(); ?>"><?php echo comments_number('Fara Comentarii', '1 Comentariu', '% Comentarii'); ?></a></em><a href="<?php the_permalink() ?>" rel="bookmark"><?php the_title(); ?></a> <em>- <?php the_time(get_option("impa_format_data")); ?></em></h2>

		<div class="postcontent"><?php the_content(__('Read more'));?></div>

		<div class="postmeta">
			<ul>
			<?php if(get_option("impa_arata_autor")){?><li><em>Postat de:</em> <?php the_author() ?></li><?}?>
			<?php if(get_option("impa_arata_categorii")){?><li><em>Categorii:</em> <?php the_category(', ') ?></li><?}?>
			<?php if(get_option("impa_arata_etichete")){?><?php the_tags('<li><em>Etichete:</em> ', ', ', ' </li>'); ?><?}?>
			<?php if(get_option("impa_arata_retele")){?><li><p>Retele sociale: <a href="http://technorati.com/faves?add=<?php the_permalink();?>">Technorati</a>, <a href="http://www.stumbleupon.com/submit?url=<?php the_permalink(); ?>">Stumble it!</a>, <a href="http://digg.com/submit?phase=2&url= <?php the_permalink();?>&title=<?php the_title();?>">Digg</a>, <a href="http://del.icio.us/post?v=4&noui&jump=close&url=<?php the_permalink();?>&title=<?php the_title();?>">de.licio.us</a>, <a href="http://myweb.yahoo.com/myresults/bookmarklet? t=<?php the_title();?>&u=<?php the_permalink();?>&ei=UTF">Yahoo</a>, <a href="http://reddit.com/submit?url=<?php the_permalink(); ?>&title=<?php the_title(); ?>" >reddit</a>, <a href="http://blogmarks.net/my/new.php? title=<?php the_title();?>&url=<?php the_permalink();?>">Blogmarks</a>, <a href="http://www.google.com/bookmarks/mark?op=edit&output=popup&bkmk=<?php the_permalink();?>&title=<?php the_title();?>">Google</a>, <a href="http://ma.gnolia.com/bookmarklet/add? url=<?php the_permalink();?>&title=<?php the_title();?>">Magnolia</a>.</p></li><?}?>
			</ul>
			<?php if(get_option("impa_arata_editeaza")){?><?php edit_post_link("editeaza") ?><?}?>
		</div>		
	</div>
<?php
}
?>